﻿using UnityEngine;
using System;

# region Location:坐标
/// <summary>
/// 一个棋盘格或棋子的坐标。
/// </summary>
[Serializable]
public struct Location
{
    public int x;//横坐标，表示棋盘上的列，范围从0至6
    public int y;//纵坐标，表示棋盘上的行，范围从0至8
    public Vector2Int Vector => new Vector2Int(x, y);//允许以Unity二维向量形式表示一个棋盘坐标——这能够方便坐标之间距离的计算

    public override string ToString()
    {
        return $"({x},{y})";
    }

    //IsNear方法:判断两个坐标是否是相邻坐标
    public bool IsNear(Location other)
    {
        if (Vector2Int.Distance(Vector, other.Vector) == 1)
        {
            return true;
        }
        return false;
    }
    public static bool IsNear(Location a, Location b)
    {
        return a.IsNear(b);
    }

    //坐标值的合法范围
    public const int Xmin = 0;
    public const int Xmax = 6;
    public const int Ymin = 0;
    public const int Ymax = 8;

    //IsValid方法:判断一个坐标是否是合法坐标，即位于棋盘范围内的坐标
    public bool IsValid()
    {
        if (x >= Xmin && x <= Xmax && y >= Ymin && y <= Ymax)
        {
            return true;
        }
        return false;
    }
    private static bool IsValid(int x, int y)
    {
        if (x >= Xmin && x <= Xmax && y >= Ymin && y <= Ymax)
        {
            return true;
        }
        return false;
    }

    //构造函数:使用一组x和y的值创建新坐标
    public Location(int x, int y)
    {
        this.x = x;
        this.y = y;
        if (!IsValid(x, y))
        {
            Debug.LogWarning($"正在创建一个超出棋盘范围的方格:({x},{y})");
        }
    }

    public static bool operator ==(Location a, Location b)
    {
        return a.Vector == b.Vector;
    }

    public static bool operator !=(Location a, Location b)
    {
        return a.Vector != b.Vector;
    }

    public override bool Equals(object obj)
    {
        return base.Equals(obj);
    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }
}
#endregion


#region Camp:阵营
/// <summary>
/// 玩家阵营。
/// </summary>
public enum Camp
{
    Neutral, Blue, Red
}
#endregion

#region Animal:动物类型
/// <summary>
/// 动物类型
/// </summary>
public enum Animal
{
    Rat = 0,
    Cat = 1,
    Dog = 2,
    Wolf = 3,
    Leopard = 4,
    Tiger = 5,
    Lion = 6,
    Elephant = 7
}
#endregion

#region SquareType:地形类型
/// <summary>
/// 棋盘方格的地形类型。
/// </summary>
public enum SquareType
{
    Land, River, Trap, Cave
}
#endregion

/*
public static class NickName_Support
{
    public static string ToNickName(this Camp camp)
    {
        string nickName = "";
        switch (camp)
        {
            case Camp.Blue:
                nickName = "蓝";
                break;
            case Camp.Red:
                nickName = "红";
                break;
        }
        return nickName;
    }
    public static string ToNickName(this Animal animal)
    {
        string nickName = "";
        switch (animal)
        {
            case Animal.Rat:
                nickName = "鼠";
                break;
            case Animal.Cat:
                nickName = "猫";
                break;
            case Animal.Dog:
                nickName = "狗";
                break;
            case Animal.Wolf:
                nickName = "狼";
                break;
            case Animal.Leopard:
                nickName = "豹";
                break;
            case Animal.Tiger:
                nickName = "虎";
                break;
            case Animal.Lion:
                nickName = "狮";
                break;
            case Animal.Elephant:
                nickName = "象";
                break;
        }
        return nickName;
    }
    public static string ToNickName(this Chessman chessman)
    {
        return $"{chessman.camp.ToNickName()}{chessman.animal.ToNickName()}";
    }
*/